package com.nc.mem.tests;

import java.nio.ByteBuffer;

import org.testng.Assert;

import com.nc.mem.serial.Serializer;
import com.nc.mem.serial.graph.asm.GraphSerializerFactory;

public class RoundTripHelper {

	public static void roundTrip(final Object o) {

		final Serializer ser = GraphSerializerFactory.serializer(o.getClass());
		final ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
		ser.write(buffer, o);
		buffer.flip();
		final Object rec = ser.read(buffer);

		Assert.assertNotSame(rec, o);
		Assert.assertEquals(rec, o);
	}

}
